package com.bjc.platform.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.bjc.platform.model.AdmCode;

/**
 * 
 * 处理与数据库adm_code表相关的持久层操作
 * 
 */
public interface AdmCodeRepo extends CrudRepository<AdmCode, Integer> {

	/**
	 * 根据adm_code.code查询对应的子类别代码数据
	 * 
	 * @param code
	 *            代码
	 * 
	 * @return 返回查询结果 List<AdmCode>
	 */
	@Query("select ac from AdmCode ac where (parentId in (select id from AdmCode where code=?1)) and (ac.code!='SOT_IW_PANCHUN')")
	List<AdmCode> queryChildrenByCode(String code);
	
	/**
	 * 根据Code查询数据字典对象
	 * @param code 代码
	 * @return
	 */
	AdmCode findByCode(String code);
	
	
	@Query("select ac from AdmCode ac,AdmCode parentAc where ac.parentId=parentAc.id and ac.code=?1 and parentAc.code=?2")
	List<AdmCode> queryCodeByCodeAndParentCode(String code,String parentCode);
}
